package com.bawei.demo_mvp.mvp;

import com.bawei.demo_mvp.base.BasePresenter;
import com.bawei.demo_mvp.entity.BaseResponse;
import com.bawei.demo_mvp.entity.VideoEntity;

import java.util.List;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * @author yaotianxue
 * @description
 * @date 2025/5/12
 */
public class VideoPresenter extends BasePresenter<VideoContract.IVideoView> implements VideoContract.IVideoPresenter {
    private VideoContract.IVideoModel model;
    public VideoPresenter() {
        model = new VideoModel();
    }
    @Override
    public void video(int currentPage, int pageSize) {
        model.video(currentPage,pageSize)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseResponse<List<VideoEntity>>>() {
                    @Override
                    public void onSubscribe(Disposable d) { //
                        mCompositeDisposable.add(d);
                    }

                    @Override
                    public void onNext(BaseResponse<List<VideoEntity>> listBaseResponse) {
                        if(isAttach()){
                            getView().showVideo(listBaseResponse.getData()); //p层请求到数据接口回调给view
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        if(isAttach()){
                            getView().onError();
                        }
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }
}
